#include <REGX52.H>
#include "Timer0.h"
#include "Nixie.h"
#include "Key.h"
#include "AT24C02.h"
#include "Delay.h"
unsigned char Min=0;
unsigned char Sec=0;
unsigned char MiniSec=0;
unsigned char Moshi=0;
void main()
{
	unsigned char Anjian=0;
	
	Timer0Init();
	while(1)
	{
		LCD_DianLiang(3,16);
		LCD_DianLiang(6,16);
		Anjian=Key_FanHui();
		LCD_DianLiang(1,Min/10);
		LCD_DianLiang(2,Min%10);
		LCD_DianLiang(4,Sec/10);
		LCD_DianLiang(5,Sec%10);
		LCD_DianLiang(7,MiniSec/10);
		LCD_DianLiang(8,MiniSec%10);
		if(Anjian==1)
		{
			Moshi=!Moshi;
		}
		if(Anjian==2)
		{
			Min=0;
			Sec=0;
			MiniSec=0;
			Moshi=0;
		}
		if(Anjian==3)
		{
			AT24C02_WriteByte(0,Min);
			Delay(5);
			AT24C02_WriteByte(1,Sec);
			Delay(5);
			AT24C02_WriteByte(2,MiniSec);
			//Moshi=0;
		}
		if(Anjian==4)
		{
			Min=AT24C02_ReadByte(0);
			Sec=AT24C02_ReadByte(1);
			MiniSec=AT24C02_ReadByte(2);
			Moshi=0;
		}
	}
}
void Int0_Rountine(void) interrupt 1
{
	static unsigned int a=0;
	static unsigned int b = 0;
	TH0=(65535-1000)/256;
	TL0=(65535-1000)%256+1;
	
	a++;
	b++;
	if(a>=20)
	{
		a=0;
		Key_DingShiQi();
	}
	if(a%2==0)
	{
		LCD_DingShiQi();
	}
	//计时
	if(b>=10&&Moshi!=0)
	{
			b=0;
			MiniSec++;
			if(MiniSec==100)
			{
				MiniSec=0;
				Sec++;
				if(Sec==60)
				{
					Min++;
					Sec=0;
					if(Min==100)
					{
						Min=0;
					}
				}
			}
	}
}
